/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.freedoit.gui;

import org.freedoit.FreeDoitConfig;

/**
 *
 * @author wanglei
 */
public class ActionPanel extends javax.swing.JPanel {

    /**
     * Creates new form ActionPanel
     */
    
    private String iconName;
    private String displayName;
    private Integer taskCount;
    
    private static final java.awt.Color COMMON_BG_COLOR = new java.awt.Color(153, 153, 153);
    private static final java.awt.Color SELECTED_BG_COLOR = new java.awt.Color(255, 255, 255);
    public ActionPanel(String iconName, String displayName, Integer taskCount) {
        this.iconName = iconName;
        this.displayName = displayName;
        this.taskCount = taskCount;

        initComponents();
    }
    
    public void addTaskCount(Integer addedCount) {
        if (this.taskCount == null || addedCount == null) {
            updateTaskCount(addedCount);
        } else {
            updateTaskCount(new Integer(addedCount.intValue() + this.taskCount.intValue()));
        }
    }
    
    public void updateTaskCount(Integer taskCount) {
        this.taskCount = taskCount;
        jLabelTaskCount.setText(taskCount != null ? taskCount.toString() : "");
    }
    
    public void setSelectedBg(boolean isSelected, java.awt.Color colorForNullCount) {
        if (jLabelTaskCount == null) {
            jLabelTaskCount.setBackground(colorForNullCount);
        } else {
            if (isSelected) {
                jLabelTaskCount.setBackground(SELECTED_BG_COLOR);
            } else {
                jLabelTaskCount.setBackground(COMMON_BG_COLOR);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelDisplay = new javax.swing.JLabel();
        jLabelTaskCount = new javax.swing.JLabel();

        jLabelDisplay.setFont(FreeDoitConfig.getFont(0, 12));
        jLabelDisplay.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabelDisplay.setIcon(new javax.swing.ImageIcon(getClass().getResource(iconName)));
        jLabelDisplay.setText(displayName);
        jLabelDisplay.setIconTextGap(14);

        jLabelTaskCount.setBackground(new java.awt.Color(153, 153, 153));
        jLabelTaskCount.setFont(FreeDoitConfig.getFont(0, 12));
        jLabelTaskCount.setText(taskCount != null ? taskCount.toString() : "");
        jLabelTaskCount.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 0, true));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelTaskCount, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabelDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                .addComponent(jLabelTaskCount))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelDisplay;
    private javax.swing.JLabel jLabelTaskCount;
    // End of variables declaration//GEN-END:variables
}
